package com.iworkh.spring.beans.bean.entity;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * 后置处理器
 *
 * @author: iworkh-沐雨云楼
 * @date: 2019-12-18
 */
public class IworkhBeanPostProcessor implements BeanPostProcessor {


    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {

        if ("lifeCycleEntity".equals(beanName)) {
            System.out.println("post process before ..." + beanName);
        }

        return null;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {

        if ("lifeCycleEntity".equals(beanName)) {
            System.out.println("post process after ..." + beanName);
            LifeCycleEntity lifeCycleEntity = new LifeCycleEntity();
            lifeCycleEntity.setAttr("post process 改变属性值");
            return  lifeCycleEntity;
        }
        return null;
    }
}
